<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<form action="logindo.php" method="post">
    <table border="1">
        <tr>
            <td>用户名</td>
            <td><input type="text" name="username" onblur="fun1()" id="username"><span id="user"></span></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="pwd"></td>
        </tr>
        <tr>
            <td><input type="submit" value="登陆"></td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    function fun1()
    {
        var username=document.getElementById("username").value;
        var ajax=new XMLHttpRequest();
        ajax.onreadystatechange=function(){
            if(ajax.readyState==4&&ajax.status==200)
            {
                if(ajax.responseText==1)
                {
                   document.getElementById("user").innerHTML="<font color='red'>用户名已存在</font>";
                   // return false;
                }
                else{
                    document.getElementById("user").innerHTML="<font color='green'>用户名是新的</font>";
                  // return true;
                }
            }
        }
        ajax.open('get','weiyi.php?username='+username,true);
        ajax.send();
    }
</script>